﻿using LevelEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine;

public static class GameGUI
{
    [CompilerGenerated]
    private static Func<string, GUIContent> <>f__am$cache4;
    private static int activeFloatField = -1;
    private static float activeFloatFieldLastValue;
    private static string activeFloatFieldString = string.Empty;
    private static int menuSelection;

    public static string AssetNameField(string value)
    {
        return AssetNameField(null, value);
    }

    public static string AssetNameField(string label, string value)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        if (label != null)
        {
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, options);
        }
        Color color = GUI.color;
        if (!AssetManager.HasAsset(value))
        {
            GUI.color = Color.red;
        }
        if (value == null)
        {
        }
        value = GUILayout.TextField(string.Empty, new GUILayoutOption[0]);
        GUI.color = color;
        Rect lastRect = GUILayoutUtility.GetLastRect();
        UIElement currentDragging = UIElement.currentDragging;
        if (((Event.current.type == EventType.MouseUp) && lastRect.Contains(Event.current.mousePosition)) && (currentDragging != null))
        {
            value = currentDragging.name;
        }
        GUILayout.EndHorizontal();
        return value;
    }

    public static bool BoolField(string label, bool value)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        if (label != null)
        {
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, options);
        }
        value = GUILayout.Toggle(value, string.Empty, new GUILayoutOption[0]);
        GUILayout.EndHorizontal();
        return value;
    }

    public static Color32 Color32Field(string label, Color32 value, bool showAlpha = false)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        if (label != null)
        {
            GUILayoutOption[] optionArray1 = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, optionArray1);
        }
        GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(200f) };
        GUILayout.BeginHorizontal(options);
        value.r = (byte) ((int) FloatField(null, (float) value.r, 0.1f));
        value.g = (byte) ((int) FloatField(null, (float) value.g, 0.1f));
        value.b = (byte) ((int) FloatField(null, (float) value.b, 0.1f));
        if (showAlpha)
        {
            value.a = (byte) ((int) FloatField(null, (float) value.a, 0.1f));
        }
        GUILayout.EndHorizontal();
        GUILayout.EndHorizontal();
        GUILayout.Space(2f);
        return value;
    }

    public static Color ColorField(string label, Color value, bool showAlpha = false)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        if (label != null)
        {
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, options);
        }
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        value.r = GUILayout.HorizontalSlider(value.r, 0f, 1f, new GUILayoutOption[0]);
        value.g = GUILayout.HorizontalSlider(value.g, 0f, 1f, new GUILayoutOption[0]);
        value.b = GUILayout.HorizontalSlider(value.b, 0f, 1f, new GUILayoutOption[0]);
        if (showAlpha)
        {
            value.a = GUILayout.HorizontalSlider(value.a, 0f, 1f, new GUILayoutOption[0]);
        }
        GUILayout.EndHorizontal();
        GUILayout.EndHorizontal();
        GUILayout.Space(2f);
        return value;
    }

    public static float FloatField(float value, float deltaValue = 0.1f)
    {
        int num = GUIUtility.GetControlID("FloatField".GetHashCode(), FocusType.Keyboard) + 1;
        if (num != 0)
        {
            float num2;
            bool flag = activeFloatField == num;
            bool flag2 = num == GUIUtility.keyboardControl;
            if ((flag2 && flag) && (activeFloatFieldLastValue != value))
            {
                activeFloatFieldLastValue = value;
                activeFloatFieldString = value.ToString();
            }
            string text = !flag ? value.ToString() : activeFloatFieldString;
            string s = GUILayout.TextField(text, new GUILayoutOption[0]);
            if (flag)
            {
                activeFloatFieldString = s;
            }
            if ((s != value.ToString()) && float.TryParse(s, out num2))
            {
                value = activeFloatFieldLastValue = num2;
            }
            if (flag2 && !flag)
            {
                activeFloatField = num;
                activeFloatFieldString = s;
                activeFloatFieldLastValue = value;
            }
            else if (!flag2 && flag)
            {
                activeFloatField = -1;
            }
            Rect lastRect = GUILayoutUtility.GetLastRect();
            GUILayout.Space(9f);
            if (deltaValue == 0f)
            {
                return value;
            }
            lastRect.x += lastRect.width + 1f;
            lastRect.width = 9f;
            lastRect.height = 9f;
            if (GUI.Button(lastRect, string.Empty))
            {
                value += deltaValue;
            }
            lastRect.y += 12f;
            if (GUI.Button(lastRect, string.Empty))
            {
                value -= deltaValue;
            }
            value = Mathf.Round(value * 10000f) / 10000f;
        }
        return value;
    }

    public static float FloatField(string label, float value, float deltaValue = 0.1f)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        if (label != null)
        {
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, options);
        }
        value = FloatField(value, deltaValue);
        GUILayout.EndHorizontal();
        return value;
    }

    public static float HorizontalSliderField(string label, float value, float min, float max)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
        GUILayout.Label(label, options);
        value = GUILayout.HorizontalSlider(value, min, max, new GUILayoutOption[0]);
        GUILayout.EndHorizontal();
        return value;
    }

    public static int IntField(int value, int deltaValue = 1)
    {
        return (int) FloatField(null, (float) value, (float) deltaValue);
    }

    public static int IntField(string label, int value, int deltaValue = 1)
    {
        return (int) FloatField(label, (float) value, (float) deltaValue);
    }

    public static void ListField<T>(string label, IList<T> list, Action<int> onDrawElement)
    {
        if (label != null)
        {
            GUILayout.Label(label, new GUILayoutOption[0]);
        }
        for (int i = 0; i < list.Count; i++)
        {
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Space(10f);
            onDrawElement(i);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(18f) };
            if (GUILayout.Button("+", options))
            {
                T item = default(T);
                list.Insert(i, item);
            }
            GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MaxWidth(18f) };
            if (GUILayout.Button("-", optionArray2))
            {
                list.RemoveAt(i);
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayout.Space(10f);
        if (GUILayout.Button("+", new GUILayoutOption[0]))
        {
            list.Add(default(T));
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(2f);
    }

    public static int Menu(string[] elements)
    {
        menuSelection = GUILayout.SelectionGrid(menuSelection, elements, 1, new GUILayoutOption[0]);
        return menuSelection;
    }

    public static bool MenuOption(int number, string text, params GUILayoutOption[] options)
    {
        return MenuOption(number, text, "Button", options);
    }

    public static bool MenuOption(int number, string text, GUIStyle style, params GUILayoutOption[] options)
    {
        return (((Event.current.character == number.ToString()[0]) && Input.GetKeyDown(number + string.Empty)) || GUILayout.Button(number + "." + text, style, options));
    }

    public static T ObjectField<T>(T value) where T: Component
    {
        Asset asset = AssetManager.GetAsset(AssetNameField(value.GetAssetName()));
        if (asset != null)
        {
            return asset.GetComponent<T>();
        }
        return null;
    }

    public static int Popup(string buttonText, string[] listContent)
    {
        if (<>f__am$cache4 == null)
        {
            <>f__am$cache4 = x => new GUIContent(x);
        }
        return Popup(buttonText, listContent.Select<string, GUIContent>(<>f__am$cache4).ToArray<GUIContent>());
    }

    public static int Popup(string buttonText, GUIContent[] listContent)
    {
        return ComboBox.List(GUILayoutUtility.GetLastRect(), buttonText, listContent, "Button");
    }

    public static void ProgressBar(float percent)
    {
        GUILayout.Box(string.Empty, new GUILayoutOption[0]);
        Rect lastRect = GUILayoutUtility.GetLastRect();
        float width = lastRect.width;
        lastRect.width = percent * width;
        Color color = GUI.color;
        GUI.color = Color.green;
        GUI.Box(lastRect, string.Empty);
        GUI.color = color;
    }

    public static void Text(string value, params GUILayoutOption[] options)
    {
        GUILayout.Label(value, options);
    }

    public static string TextArea(string value)
    {
        return TextArea(null, value);
    }

    public static string TextArea(string label, string value)
    {
        if (label != null)
        {
            GUILayoutOption[] optionArray1 = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, optionArray1);
        }
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayout.Space(10f);
        if (value == null)
        {
        }
        GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandHeight(true) };
        value = GUILayout.TextArea(string.Empty, options);
        GUILayout.EndHorizontal();
        return value;
    }

    public static string TextField(string value)
    {
        return TextField(null, value);
    }

    public static string TextField(string label, string value)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        if (label != null)
        {
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label(label, options);
        }
        if (value == null)
        {
        }
        value = GUILayout.TextField(string.Empty, new GUILayoutOption[0]);
        GUILayout.EndHorizontal();
        return value;
    }

    public static void Tooltip(string text)
    {
        <Tooltip>c__AnonStorey50 storey = new <Tooltip>c__AnonStorey50 {
            text = text
        };
        if (Event.current.alt)
        {
            <Tooltip>c__AnonStorey4F storeyf = new <Tooltip>c__AnonStorey4F {
                rect = GUILayoutUtility.GetLastRect()
            };
            Event current = Event.current;
            if (storeyf.rect.Contains(current.mousePosition))
            {
                <Tooltip>c__AnonStorey51 storey2 = new <Tooltip>c__AnonStorey51 {
                    <>f__ref$80 = storey,
                    <>f__ref$79 = storeyf,
                    style = new GUIStyle(GUI.skin.box)
                };
                storey2.style.normal.textColor = Color.black;
                Vector2 vector = storey2.style.CalcSize(new GUIContent(storey.text));
                storeyf.rect.position = GUIUtility.GUIToScreenPoint(current.mousePosition);
                storeyf.rect.size = vector;
                storeyf.rect.position -= (Vector2) (storeyf.rect.size.y * Vector2.up);
                Singleton<GameGUIHelper>.Instance.Draw(new Action(storey2.<>m__76));
            }
        }
    }

    public static Vector3 Vector3Field(string label, Vector3 value)
    {
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
        GUILayout.Label(label, options);
        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
        value.x = FloatField(null, value.x, 1f);
        value.y = FloatField(null, value.y, 1f);
        value.z = FloatField(null, value.z, 1f);
        GUILayout.EndHorizontal();
        GUILayout.EndHorizontal();
        GUILayout.Space(2f);
        return value;
    }

    [CompilerGenerated]
    private sealed class <Tooltip>c__AnonStorey4F
    {
        internal Rect rect;
    }

    [CompilerGenerated]
    private sealed class <Tooltip>c__AnonStorey50
    {
        internal string text;
    }

    [CompilerGenerated]
    private sealed class <Tooltip>c__AnonStorey51
    {
        internal GameGUI.<Tooltip>c__AnonStorey4F <>f__ref$79;
        internal GameGUI.<Tooltip>c__AnonStorey50 <>f__ref$80;
        internal GUIStyle style;

        internal void <>m__76()
        {
            GUI.Label(this.<>f__ref$79.rect, this.<>f__ref$80.text, this.style);
        }
    }
}

